package sale.wxb.loveshopping.security;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import sale.wxb.loveshopping.entity.common.Result;
import sale.wxb.loveshopping.enums.ResponseEnum;
import sale.wxb.loveshopping.utils.SecurityUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * security 认证失败，异常处理
 */
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        // 这边固定返回未登录
        Result<Object> fail = Result.fail(ResponseEnum.NOT_LOGIN);
        SecurityUtil.writeResponse(response, fail);
    }
}
